<?php
App::uses('AppController', 'Controller');
/**
 * Seats Controller
 *
 * @property Seat $Seat
 */
class SeatsController extends AppController {

/**
 * index method
 *
 * @return void
 */
	public function index() {
		$this->Seat->recursive = 0;
		$this->set('seats', $this->paginate());
	}

/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function view($id = null) {
		$this->Seat->id = $id;
		if (!$this->Seat->exists()) {
			throw new NotFoundException(__('Invalid seat'));
		}
		$this->set('seat', $this->Seat->read(null, $id));
	}

/**
 * add method
 *
 * @return void
 */
	public function add() {
		if ($this->request->is('post')) {
			$this->Seat->create();
			if ($this->Seat->save($this->request->data)) {
				$this->Session->setFlash(__('The seat has been saved'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The seat could not be saved. Please, try again.'));
			}
		}
		$seatTypes = $this->Seat->SeatType->find('list');
		$theathers = $this->Seat->Theather->find('list');
		$this->set(compact('seatTypes', 'theathers'));
	}

/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function edit($id = null) {
		$this->Seat->id = $id;
		if (!$this->Seat->exists()) {
			throw new NotFoundException(__('Invalid seat'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			if ($this->Seat->save($this->request->data)) {
				$this->Session->setFlash(__('The seat has been saved'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The seat could not be saved. Please, try again.'));
			}
		} else {
			$this->request->data = $this->Seat->read(null, $id);
		}
		$seatTypes = $this->Seat->SeatType->find('list');
		$theathers = $this->Seat->Theather->find('list');
		$this->set(compact('seatTypes', 'theathers'));
	}

/**
 * delete method
 *
 * @throws MethodNotAllowedException
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function delete($id = null) {
		if (!$this->request->is('post')) {
			throw new MethodNotAllowedException();
		}
		$this->Seat->id = $id;
		if (!$this->Seat->exists()) {
			throw new NotFoundException(__('Invalid seat'));
		}
		if ($this->Seat->delete()) {
			$this->Session->setFlash(__('Seat deleted'));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('Seat was not deleted'));
		$this->redirect(array('action' => 'index'));
	}

	public function updateStatus($id = null){
		$this->Seat->id = $id;
		if ($this->request->is('post') || $this->request->is('put')) {
			if ($this->Seat->save($this->request->data)) {
				$this->Session->setFlash(__('The seat has been saved'));
				$this->set('seat', $this->Seat->read(null, $id));
				$this->render('seat', 'ajax');
				#$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The seat could not be saved. Please, try again.'));
			}
		} else {
			$this->request->data = $this->Seat->read(null, $id);
			$seatTypes = $this->Seat->SeatType->find('list');
			$this->set(compact('seatTypes'));
			$this->render('update_status','ajax'); 
		}
	}
	
}
